#include "Config.h"
#include "Logging.h"
#include <fstream>
#include <iostream>

Config globalConfig;

Config::Config()
{
	
}

bool Config::saveConfig()
{
	std::ofstream ofs("server.ini");
	
	return true;
}

bool Config::loadConfig()
{
	std::ifstream ifs("server.ini", std::ios::in);
	
	getline(ifs, serverIP); //FIXME carriage return etc
	logMessage("Server IP: " + serverIP);
	getline(ifs, localPlayerName);
	if(localPlayerName.length() > 10)
	{
		logMessage("Player name is too long.\n");
		return false;
	}

	logMessage("Player name:" + localPlayerName);
	
	if(serverIP == "127.0.0.1")
	{
		isServer = true;
	}
	
	ifs.close();

	screenWidth = 640;
	screenHeight = 480;
	screenFullscreen = false;
	
	return true;
}

std::string Config::getLocalPlayerName()
{
	return localPlayerName;
}

bool Config::setLocalPlayerName(std::string passedName)
{
	localPlayerName = passedName;
	return true;
}


std::string Config::getServerIP()
{
	return serverIP;
}

bool Config::getIsServer()
{
	return isServer;
}

unsigned int Config::getScreenWidth()
{
	return screenWidth;
}

unsigned int Config::getScreenHeight()
{
	return screenHeight;
}

bool Config::getScreenFullscreen()
{
	return screenFullscreen;
}

void Config::setResolution(const unsigned int width, const unsigned int height)
{
	screenWidth = width;
	screenHeight = height;
}
